<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('查看值班')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: select2-js" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-message-edit" th:object="${tmdDutyMessage}">
            <input name="id" th:value="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">编号：</label>
                <div class="col-sm-8">
                    <input name="id" th:value="*{id}" class="form-control" type="text" disabled>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">名称：</label>
                <div class="col-sm-8">
                    <input name="dutyName" th:value="*{dutyName}" class="form-control" type="text" disabled>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">排班名称：</label>
                <div class="col-sm-8">
                    <select id="arrangeNameId" name="arrangeNameId" class="form-control" disabled>
                        <option th:text="*{arrangeName}" th:value="*{arrangeNameId}" th:selected="true" disabled></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">值班人：</label>
                <div class="col-sm-8">
                    <select class="form-control dutyPerson" id="dutyPersonId" name="dutyPersonId" disabled>
                        <option th:text="*{userName}" th:value="*{dutyPersonId}" th:selected="true" disabled></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">值班时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input type="text" id="dutyTime" class="form-control laydate-demo-2" name="dutyTime" placeholder="--请选择日期--"  th:value="*{#dates.format(dutyTime, 'yyyy-MM-dd')}" disabled>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">联系人：</label>
                <div class="col-sm-8">
                    <select id="linkman" name="linkmanId" class="form-control" disabled>
                        <option th:text="*{linkman}" th:value="*{linkmanId}" th:selected="true" disabled></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">联系方式：</label>
                <div class="col-sm-8">
                    <select id="phonenumber" name="phonenumber" class="form-control" disabled>
                        <option th:text="*{phonenumber}" th:value="*{phonenumber}" th:selected="true"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">创建人：</label>
                <div class="col-sm-8">
                    <input name="createPerson" th:value="*{createPerson}" class="form-control" type="text" disabled>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">创建时间：</label>
                <div class="col-sm-8">
                    <input name="createTime" class="form-control" type="text" th:value="${#dates.format(#dates.createNow(), 'yyyy-MM-dd HH:mm:ss')}" disabled />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
                    <select name="dutyStatus" class="form-control m-b" th:with="type=${@dict.getType('duty_status')}" disabled>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${dict.dictValue}==*{dutyStatus}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="notes" class="form-control" disabled>[[*{notes}]]</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">附件：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="file" th:value="*{file}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="file" name="file" type="file" disabled>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "system/message";
        $("#form-message-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-message-edit').serialize());
            }
        }

        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });
    </script>
    <script th:inline="javascript">
        $(document).ready(function() {
            $.ajax({
                url: ctx + "system/application/getAllApp",
                type: 'GET',
                success:function (data) {
                    <!--清空下拉框中的缓存-->
                    // $("#arrangeNameId").empty();
                    <!--避免下拉框的值不变-->
                    $("#arrangeNameId").append("<option value=''>请选择排班</option>");
                    for (var i = 0; i < data.length; i++){
                        $("#arrangeNameId").append("<option value='" + data[i].id + "'>" + data[i].arrangeName + "</option>");
                    }
                }
            });
            $("#arrangeNameId").change(function () {//同上面一样
                // alert($("#deptId").val())
                $.ajax({
                    url: ctx + "system/people/getPeople",
                    type: 'GET',
                    data: {
                        //注意：此处传递的值的名字id必须和后端接受的相同，否则接收不到
                        id: $("#arrangeNameId").val(),
                    },
                    success:function (data) {
                        $("#dutyPersonId").empty();
                        $("#dutyPersonId").append("<option value=''>请选择值班人</option>");
                        for (var i = 0; i < data.length; i++){
                            $("#dutyPersonId").append("<option value='" + data[i].dutyPersonId + "'>" + data[i].userName + "</option>");
                        }
                    }
                });
            });
            $.ajax({
                url: ctx + "system/user/getAllUserList",
                type: 'GET',
                success:function (data) {
                    // $("#linkman").empty();
                    $("#linkman").append("<option value=''>请选择联系人</option>");
                    for (var i = 0; i < data.length; i++){
                        $("#linkman").append("<option value='" + data[i].userId + "'>" + data[i].userName + "</option>");
                    }
                }
            });
            $("#linkman").change(function () {//同上面一样
                $.ajax({
                    url: ctx + "system/user/getUserByUserId",
                    type: 'GET',
                    data: {
                        id: $("#linkman").val(),
                    },
                    success:function (data) {
                        $("#phonenumber").empty();
                        $("#phonenumber").append("<option value='" + data.phonenumber + "'>" + data.phonenumber + "</option>");
                    }
                });
            });
        });
        $(function(){
            <!-- laydate示例 -->
            layui.use('laydate', function(){
                var laydate = layui.laydate;

                laydate.render({
                    elem: '#dutyTime',
                    type: 'date'
                });
            });
        });
    </script>
</body>
</html>